package com.sphd.Restaurant.presenter;

import android.util.Log;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.infos.RestaurantInfo;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.OftenV;


import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/9/28.
 */

public class OftenP extends BasePresenter implements VolleyCallBack<JSONObject> {
    OftenV oftenV;

    public OftenP(OftenV oftenV) {
        this.oftenV = oftenV;
    }

    @Override
    public void addData(String url) {
        oftenV.showdialog();
        sendJsonObjectUrl(url, this);
    }

    @Override
    public void onResponse(JSONObject jsonObject) {
        Log.e("P===",jsonObject.toString());
        try {
            if (!jsonObject.getString("res") .equals("[]")) {
                List<RestaurantInfo> getmsg = myJson.getAllRestaurantList(jsonObject);
                oftenV.refreshList(getmsg);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        oftenV.dissmissdialog();
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        oftenV.dissmissdialog();
        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
    }
}
